//
//  SGdownloader.h
//  downloadManager
//
//  Created by Htain Lin Shwe on 11/7/12.
//  Copyright (c) 2012 Edenpod. All rights reserved.
//

#import <Foundation/Foundation.h>
//for block

typedef void (^HCSGDownloadProgressBlock)(float progressValue,NSInteger percentage);
typedef void (^HCSGDowloadFinished)(NSData* fileData);
typedef void (^HCSGDownloadFailBlock)(NSError*error);


@protocol HCSGdownloaderDelegate <NSObject>

@required
-(void)HCSGDownloadProgress:(float)progress Percentage:(NSInteger)percentage;
-(void)HCSGDownloadProgress2:(float)progress Percentage2:(NSInteger)percentage;
-(void)HCSGDownloadProgress3:(float)progress Percentage3:(NSInteger)percentage;
-(void)HCSGDownloadProgress4:(float)progress Percentage4:(NSInteger)percentage;
-(void)HCSGDownloadProgress5:(float)progress Percentage5:(NSInteger)percentage;
-(void)HCSGDownloadProgress6:(float)progress Percentage6:(NSInteger)percentage;
-(void)HCSGDownloadFinished:(NSData*)fileData;
-(void)HCSGDownloadFinished2:(NSData*)fileData;
-(void)HCSGDownloadFinished3:(NSData*)fileData;
-(void)HCSGDownloadFinished4:(NSData*)fileData;
-(void)HCSGDownloadFinished5:(NSData*)fileData;
-(void)HCSGDownloadFinished6:(NSData*)fileData;

-(void)HCSGDownloadFail:(NSError*)error;
@end

@interface HCSGdownloader : NSObject <NSURLConnectionDataDelegate>

//properties
@property (nonatomic,readonly) NSMutableData* receiveData;
@property (nonatomic,readonly) NSInteger downloadedPercentage;
@property (nonatomic,readonly) float progress;
@property (nonatomic,assign) int flag;

@property (nonatomic,strong) id<HCSGdownloaderDelegate>delegate;
//initwith file URL and timeout
-(id)initWithURL:(NSURL *)fileURL timeout:(NSInteger)timeout;

-(void)startWithDownloading:(HCSGDownloadProgressBlock)progressBlock onFinished:(HCSGDowloadFinished)finishedBlock onFail:(HCSGDownloadFailBlock)failBlock;

-(void)startWithDelegate:(id<HCSGdownloaderDelegate>)delegate;
-(void)cancel;
@end
